'use client'

import { useEffect } from 'react'
import { Provider } from 'react-redux'
import store from '@/store'
import { setUser } from '@/store/user-slice'
import { setCurProject } from '@/store/project-slice'

export function ReduxProvider({ children }) {
  useEffect(() => {
    const user = localStorage.getItem('user')
    if (user) {
      store.dispatch(setUser(JSON.parse(user)))
    }
    const curProject = localStorage.getItem('curProject')
    if (curProject) {
      store.dispatch(setCurProject(JSON.parse(curProject)))
    }
  }, [])

  return <Provider store={store}>{children}</Provider>
}
